<template>
  <div class='dept-select'>
    <treeselect v-model="deptId" :options="deptOptions" :normalizer="normalizer" placeholder="请选择部门" @select="changeDept" />
  </div>
</template>

<script>
import { userDeptTreeSelect } from "@/api";
import { handleTree } from '@/utils/ruoyi'
export default {
  data () {
    return {
      deptId: '',
      projectPointId: '',
      deptOptions: []
    };
  },
  computed: {},
  watch: {},
  created () {
    userDeptTreeSelect().then(res => {
      if (res.code === 200) {
        this.deptOptions = res.data
        this.deptId = res.data[0].id
        this.projectPointId = res.data[0].projectPointId
        this.$emit('changeDept', this.deptId,this.projectPointId)
      }
    });
  },
  methods: {
    /** 转换部门数据结构 */
    normalizer (node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.label,
        children: node.children
      }
    },
    changeDept (item) {
      this.$emit('changeDept', item.id,item.projectPointId)
    }
  },

  mounted () {

  },
  components: {},
}
</script>

<style lang='less' scoped>
.dept-select {
  width: 13%;
  z-index: 4;
  position: absolute;
  top: 55px;
  left: 20px;
}
</style>